package com.yuji.aacar.controller.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.yuji.aacar.widgets.pulltorefresh.adapter.WbaseRecycleAdapter;
import com.yuji.aacar.widgets.pulltorefresh.remove.WptrRemoveDragView;

import java.util.ArrayList;
import java.util.List;

/**
 * <li>Package:com.yuji.aacar.controller.adapter</li>
 * <li>Author: lining </li>
 * <li>Date: 2018/3/2</li>
 * <li>Description:   </li>
 */

public class CommonRemoveAdapter extends WbaseRecycleAdapter {

    Context mContext;
    List<WptrRemoveDragView> views = new ArrayList<WptrRemoveDragView>();
    WptrRemoveDragView.DragStateListener listener;

    public CommonRemoveAdapter(Context context) {
        super(context);
        mContext = context;
    }

    public CommonRemoveAdapter(Context context, WptrRemoveDragView.DragStateListener listener) {
        super(context);
        mContext = context;
        this.listener = listener;
    }

    @Override
    public void wOnBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        Log.e("--wOnBindViewHolder--", viewHolder.toString());

        if(viewHolder != null){
            WptrRemoveDragView view = viewHolder.dv;
            viewHolder.tv.setText(data.get(position)+"");
            view.setTag(position);

            views.add(view);
            //            view.setOnDragStateListener(listener);
            view.setOnDragStateListener(new WptrRemoveDragView.DragStateListener() {
                @Override
                public void onOpened(WptrRemoveDragView dragView) {
                    Log.e("--onOpened--", dragView.toString());
                }

                @Override
                public void onClosed(WptrRemoveDragView dragView) {
                    Log.e("--onClosed--", dragView.toString());
                }

                @Override
                public void onForegroundViewClick(WptrRemoveDragView dragView , View v) {

                    Log.e("--onForeground--", dragView.toString());

                    int pos = (int) dragView.getTag();
                    Toast.makeText(mContext , "click item" + pos , Toast.LENGTH_SHORT).show();
                }

                @Override
                public void onBackgroundViewClick(WptrRemoveDragView dragView , View v) {
                    Log.e("--onBackgroundView--", dragView.toString());

                    int pos = (int) dragView.getTag();

                    views.remove(pos);
                    notifyDataSetChanged();

                    Log.e("--views--", views.size()+"");
                    Log.e("--pos--", pos+"");

                }
            });
        }
    }

    @Override
    public RecyclerView.ViewHolder wOnCreateViewHolder(ViewGroup parent, int viewType) {
        return null;
    }

    @Override
    public int getHeaderLayoutId() {
        return 0;
    }

    @Override
    public int getFooterLayoutId() {
        return 0;
    }

    @Override
    public int getNoDataLayoutId() {
        return 0;
    }


    class ViewHolder extends RecyclerView.ViewHolder{
        WptrRemoveDragView dv;
        TextView tv;

        public ViewHolder(View itemView) {
            super(itemView);
//            dv = (WptrRemoveDragView) itemView.findViewById(R.id.drag_view);
//            tv = (TextView) itemView.findViewById(R.id.tv);
        }
    }
}
